//
//  MoviePostCollectionView.m
//  MyMovie
//
//  Created by apple on 16/5/17.
//  Copyright © 2016年 ljp. All rights reserved.
//

#import "MoviePostCollectionView.h"
#import "MovieCellCollectionViewCell.h"

@interface MoviePostCollectionView ()
{
    CGSize _cellSize;
}

@end

@implementation MoviePostCollectionView


////重写设置器方法,重新加载数据
//- (void)setMovieArray:(NSArray *)movieArray {
//
//    self.movieArray = movieArray;
//    [self reloadData];
//}


- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath  {

    MovieCellCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"MovieCellCollectionViewCell" forIndexPath:indexPath];

    cell.movie = self.movieArray[indexPath.item];

    return cell;

}


-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {

    CGFloat xOffset = collectionView.contentOffset.x;
    CGFloat width = (self.height-84)/1.7 + 20;
    CGFloat index = xOffset / width;
    NSInteger indexInteger = index + 0.5;

    self.currentIndex = indexPath.item;

    if (indexInteger == indexPath.item) {

        MovieCellCollectionViewCell *cell = (MovieCellCollectionViewCell *)[collectionView cellForItemAtIndexPath:indexPath];
        [cell flipCell];

    }else {

        [collectionView scrollToItemAtIndexPath:indexPath atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally animated:YES];

    }
}

- (void)collectionView:(UICollectionView *)collectionView didEndDisplayingCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath {

    MovieCellCollectionViewCell *movieCellCollectionViewCell = (MovieCellCollectionViewCell *)cell;
    [movieCellCollectionViewCell restore];
}

@end
